package com.chief.hadoop.mr.writable;

import org.apache.hadoop.io.LongWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Mapper;

import java.io.IOException;

public class FlowMapper extends Mapper<LongWritable, Text, Text, FlowBean> {

    FlowBean outValue = null;
    Text outKey = new Text();

    @Override
    protected void map(LongWritable key, Text value, Context context) throws IOException, InterruptedException {
        String line = value.toString();
        String[] split = line.split("\t");
        outValue = new FlowBean(Long.parseLong(split[split.length - 3]), Long.parseLong(split[split.length - 2]));
        outKey.set(new Text(split[1]));
        context.write(outKey, outValue);
    }

}
